﻿@using CoreData
@using Helper
@model List<ShoppingCart>
@{
    Layout = null;
}
@{
    var toTalProduct = 0;
    var toTalPrice = 0;
    if (Model != null)
    {
        foreach (var item in Model)
        {
            toTalProduct = toTalProduct + item.Amount;
        }
        foreach (var item in Model)
        {
            toTalPrice = toTalPrice + item.TotalItemPrice;
        }
    }
}
@if (Model != null && Model.Count() > 0)
{
    double total = 0;
    using (Html.BeginForm("UpdateCart", "ShoppingCart", FormMethod.Post))
    {
    <table class="cart-table">
        <thead>
            <tr>
                <th>
                    <input type="checkbox" class="chk chk-all" />
                </th>
                <th>
                    Sản phẩm
                </th>
                <th>
                    Đơn giá
                </th>
                <th>
                    Số lượng
                </th>
                <th>
                    Thành tiền
                </th>
                <th>
                    Xóa
                </th>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model)
            {
                total += item.Amount * item.Product.Price;
                <tr>
                    <td class="checkbox-cart">
                        <input name="ID" chkid="@item.Product.ID" class="chk-item" type="checkbox" />
                    </td>
                    <td>
                        <a href="@Url.RouteUrl("product_details", new { Id = item.Product.ID, Link = item.Product.Link })">@item.Product.Name</a>
                    </td>
                    <td class="single-price">@Helper.StringHelper.FormatCurrencyVN(item.Price)
                    </td>
                    <td>@Html.TextBoxFor(x => item.Amount, new { @class = "txt txt-count qty", productId = item.Product.ID })
                        @Html.HiddenFor(x => item.Product.ID, new { Name = "p_qty", Value = (item.Product.ID + "," + item.Amount) })
                    </td>
                    <td class="amount-price">@Helper.StringHelper.FormatCurrencyVN(item.TotalItemPrice)
                    </td>
                    <td>
                        <a href="@Url.Action("RemoveFromCart", "ShoppingCart", new { productid = item.Product.ID })" href="javascript:void(0)" class="btn btn-icon btn-delete">
                        </a>
                    </td>
                </tr>
            }
        </tbody>
    </table>
    <div class="cart-detail-footer">
        <div class="footer-tool">
            <a class="btn-icon btn-delete-select" title="Xóa giỏ hàng được chọn" href="javascript:void(0)">
            </a>
            <p>
                Tổng tiền: <span class="totalPrice" id="totalPrice">@Helper.StringHelper.FormatCurrencyVN(toTalPrice)</span></p>
            <div class="checkout-cart-tool">
                <a class="btn gray" href="@Url.Action("Index", "Home")">Tiếp tục mua hàng</a>
                <a class="btn" href="@Url.Action("Index", "Payment")">Thanh Toán</a>
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="clearfix"></div>
    </div>
    }
}
else
{ 
    <span>Bạn chưa có giỏ hàng nào :(</span>
}
